/* Simple line class */
class Line
{
 public:
  Line(double x1, double y1, double x2, double y2) :
    x1(x1), y1(y1), x2(x2), y2(y2)
  {
    assert(x2 != x1);
    assert(y2 != y1);
    dy = y2-y1;
    dx = x2-x1;
    m = dy/dx;
    b = y1 - m*x1;
  }

  double f(double x) {
    return m*x+b;
    //return dy * (x-x1) / dx + y1;
  }

  double f_inv(double y) {
    return (y-b)/m;
  }

 private:
  double x1, y1, x2, y2;
  double dy, dx;
  double m, b;
};

